<template>
  <div class="app-container">
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets" style="margin-top: 5px"></i>
      <span style="margin-top: 5px">数据列表</span>
      <el-button
        class="btn-add"
        @click="handleAdd()"
        style="float:right"
        size="mini">
        添加
      </el-button>
    </el-card>

    <div class="table-container">
      <el-table
        :key="tableKey"
        v-loading="listLoading"
        :data="list"
        border
        fit
        highlight-current-row
        style="width: 100%;margin-top:20px;"
        >
        <el-table-column label="编号" align="center">
          <template slot-scope="scope">
            {{scope.row.id}}
          </template>
        </el-table-column>
        <el-table-column label="名称" align="center">
          <template slot-scope="scope">
            {{scope.row.name}}
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center">
          <template slot-scope="scope">
            {{scope.row.note}}
          </template>
        </el-table-column>
        <el-table-column label="时间" align="center">
          <template slot-scope="scope">
            {{scope.row.updated_time}}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleBoomItems(scope.row)">详情
            </el-button>
            <el-button
              size="mini"
              @click="handleUpdate(scope.row)">编辑
            </el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination
    v-show="total>0"
    :total="total"
    :page.sync="listQuery.page"
    :limit.sync="listQuery.limit"
    @pagination="fetchData" />
  </div>
</template>

<script>
  import {
    fetchElectronicBoomList,
    createElectronicBoom,
    updateElectronicBoom,
    deleteElectronicBoom
  } from '@/api/electronicBoom'
  import Pagination from '@/components/Pagination' // secondary package based on el-pagination

  export default {
    name: "electronicBoom",
    components: { Pagination },
    data() {
      return {
        tableKey: 0,
        list: null,
        listLoading: true,
        total: 10,
        listQuery: {
          page: 1,
          limit: 10
        },
        parentId: 0
      }
    },
    created() {
      this.fetchData();
    },
    methods: {
      fetchData() {
        this.listLoading = true
        console.log(this.listQuery)
        fetchElectronicBoomList(this.listQuery).then(response => {
          this.list = response.data.items
          this.total = response.data.total
          this.listLoading = false
        });
      },
      handleAdd(row) {
        this.$router.push({ path: '/sdc/electronicBoomAdd' })
      },
      handleDelete(row) {
        this.$confirm('是否要删除该boom单', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteElectronicBoom(row.id).then(response => {
            this.$message(response.message)
            this.fetchData()
          });
        });
      },
      handleUpdate(row) {
        this.$router.push({
          path: '/sdc/electronicBoomUpdate',
          query: row
        })
      },
      handleBoomItems(row) {
        this.$router.push({
          path: '/sdc/electronicBoomItem',
          query: {'id':row.id}
        })
      }
    }
  }
</script>

<style scoped>

</style>
